package com.siao.example.libaray.component.view
{
	import com.siao.component.BytesBitmap;
	import com.siao.component.Orientation;
	import com.siao.component.scroller.ScrollBar;
	import com.siao.component.scroller.ScrollPanel;
	import com.siao.component.scroller.ScrollRect;
	import com.siao.display.Align;
	import com.siao.display.LayoutElement;
	import com.siao.events.BytesEvent;
	import com.siao.example.common.configuration.LibarayDisplayImageConfiguration;
	import com.siao.example.common.ui.Layer;
	import com.siao.mvc.View;
	
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	
	/**
	 * 滚动面板视图
	 * @author SiaoLeon
	 */
	public class ComponentScrollPanelView extends View
	{
		// -------------------------------------------------------------------------------------------------------- 静态常量
		
		// -------------------------------------------------------------------------------------------------------- 静态变量
		
		// -------------------------------------------------------------------------------------------------------- 静态方法
		
		// -------------------------------------------------------------------------------------------------------- 静态函数
		
		// -------------------------------------------------------------------------------------------------------- 属性
		
		// -------------------------------------------------------------------------------------------------------- 变量
		
		private var panel:ScrollPanel;
		
		private var rect:ScrollRect;
		
		// -------------------------------------------------------------------------------------------------------- 构造
		
		/**
		 * 构造函数
		 */
		public function ComponentScrollPanelView()
		{
			super();
			
			//生成垂直滚动条
			var backgroundV:Sprite = new Sprite();
			backgroundV.graphics.beginFill(0X000000, 0.8);
			backgroundV.graphics.drawRect(0, 0, 12, 100);
			backgroundV.graphics.endFill();
			
			var dragV:Sprite = new Sprite();
			dragV.graphics.beginFill(0XFF0000, 1);
			dragV.graphics.drawRect(0, 0, 20, 40);
			dragV.graphics.endFill();
			
			var prevV:Sprite = new Sprite();
			prevV.graphics.beginFill(0XFF0000, 0.8);
			prevV.graphics.drawRect(0, 0, 20, 20);
			prevV.graphics.endFill();
			
			var nextV:Sprite = new Sprite();
			nextV.graphics.beginFill(0XFF0000, 0.8);
			nextV.graphics.drawRect(0, 0, 20, 20);
			nextV.graphics.endFill();
			
			var vScrollBar:ScrollBar = new ScrollBar(Orientation.VERTICAL, backgroundV, dragV, prevV, nextV);
			
			//生成水平滚动条
			var backgroundH:Sprite = new Sprite();
			backgroundH.graphics.beginFill(0X000000, 0.8);
			backgroundH.graphics.drawRect(0, 0, 100, 12);
			backgroundH.graphics.endFill();
			
			var dragH:Sprite = new Sprite();
			dragH.graphics.beginFill(0XFF0000, 1);
			dragH.graphics.drawRect(0, 0, 40, 20);
			dragH.graphics.endFill();
			
			var prevH:Sprite = new Sprite();
			prevH.graphics.beginFill(0XFF0000, 0.8);
			prevH.graphics.drawRect(0, 0, 20, 20);
			prevH.graphics.endFill();
			
			var nextH:Sprite = new Sprite();
			nextH.graphics.beginFill(0XFF0000, 0.8);
			nextH.graphics.drawRect(0, 0, 20, 20);
			nextH.graphics.endFill();
			
			var hScrollBar:ScrollBar = new ScrollBar(Orientation.HORIZONTAL, backgroundH, dragH, prevH, nextH);
			
			var content:LayoutElement = new LayoutElement();
			content.draw(0XFF00FF, 0.4);
			content.width = 800;
			content.height = 240;
			
			this.panel = new ScrollPanel(content, vScrollBar, hScrollBar);
			this.panel.draw(0X0F0F0F, 0.2);
			this.panel.marginTop = 80;
			this.panel.marginBottom = 220;
			this.panel.marginRight = 450;
			this.panel.padding = 5;
			this.panel.maskMarginLeft = 5;
			this.panel.maskMarginRight = 15;
			this.panel.maskMarginBottom = 10;
			this.panel.scrollWheel = true;
			this.panel.scrollEasing = true;
			this.panel.scrollDrag = true;
			this.panel.overDrage = 150;
			
			//生成内容
			var bitmap:BytesBitmap = new BytesBitmap(LibarayDisplayImageConfiguration.BitmapPath);
			bitmap.width = bitmap.height = 2000;
			bitmap.addEventListener(BytesEvent.COMPLETE, onLoadComplete);
			
			this.rect = new ScrollRect(bitmap);
			this.rect.draw(0X0F0F0F, 0.2);
			this.rect.alignH = Align.RIGHT;
			this.rect.width = 300;
			this.rect.marginTop = 80;
			this.rect.marginBottom = 250;
			this.rect.padding = 10;
			this.rect.maskMarginLeft = 5;
			this.rect.maskMarginRight = 15;
			this.rect.scrollEasing = true;
			this.rect.scrollDrag = true;
			this.rect.overDrage = 150;
		}
		
		// -------------------------------------------------------------------------------------------------------- 方法
		
		override public function onAdd():void
		{
			Layer.instance.content.addChild(this.panel);
			Layer.instance.content.addChild(this.rect);
		}
		
		override public function onRemove():void
		{
			Layer.instance.content.removeChild(this.panel);
			Layer.instance.content.removeChild(this.rect);
		}
		
		// -------------------------------------------------------------------------------------------------------- 函数
		
		private function onLoadComplete(event:BytesEvent):void
		{
			//			this.panel.content = event.target as DisplayObject;
			this.rect.content = event.target as DisplayObject;
			this.rect.moveTo(0, 0);
		}
	
	}
}
